<template>
  <div>
    <div class="search">
      <el-input
        style="width: 200px; margin-right: 10px"
        size="small"
        v-model="form.username"
        placeholder="请输入用户名"
      ></el-input>
      <el-button type="info" size="small" @click="chaxun()" plain
        >查询</el-button
      >
      <el-button type="warning" size="small" @click="chongzhi()" plain
        >重置</el-button
      >
    </div>
    <div class="table">
      <el-table :data="tabledata">
        <el-table-column label="序号" type="index" width="50"></el-table-column>
        <el-table-column label="用户名" prop="username"></el-table-column>
        <el-table-column label="电话" prop="phone"></el-table-column>
        <el-table-column label="邮箱" prop="email"></el-table-column>
        <el-table-column label="头像" prop="avator"></el-table-column>
        <el-table-column label="状态" prop="status">
          <template slot-scope="scope">
            <span v-if="scope.row.status == '0'">待审核</span>
            <span v-if="scope.row.status == '1'">已封禁</span>
            <span v-if="scope.row.status == '2'">已通过</span>
          </template>
        </el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button
              type="primary"
              plain
              v-if="scope.row.status == 0"
              @click="sh(scope.row)"
              >审核</el-button
            >
            <el-button
              type="danger"
              @click="fj(scope.row)"
              plain
              v-if="scope.row.status == 2"
              >封禁</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <el-pagination background layout="total,prev, pager, next" :total="total"  @size-change="handleSizeChange"
      @current-change="handleCurrentChange">
      </el-pagination>
    </div>
    <el-dialog
      title="审核"
      :visible.sync="dialogVisible"
      width="30%"
      :before-close="handleClose"
    >
      <el-form :model="form1">
        <el-form-item label="审核结果">
          <el-radio-group v-model="form1.status">
            <el-radio label="0">驳回</el-radio>
            <el-radio label="2">通过</el-radio>
          </el-radio-group>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="shenheqd">确 定</el-button>
      </span>
    </el-dialog>
    <el-dialog
      title="封禁"
      :visible.sync="dialogVisible1"
      width="30%"
      :before-close="handleClose1"
    >
      <el-form :model="form1">
        <el-form-item label="封禁原因">
          <el-input
            v-model="form1.fjly"
            type="textarea"
            placeholder="请输入封禁原因"
          ></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible1 = false">取 消</el-button>
        <el-button type="primary" @click="fjqd">确 定</el-button>
      </span></el-dialog
    >
  </div>
</template>
<script>
import service from "../request";

export default {
  data() {
    return {
      form: {
        username: "",
        pageNum: 1,
        pageSize: 10,
      },
      form1: {},
      dialogVisible1: false,
      dialogVisible: false,

      total: 0,
      tabledata: [],
    };
  },
  mounted() {
    this.getdata();
  },
  methods: {
      handleCurrentChange(e){
          this.form.pageNum=e;
          this.getdata()
      },
      handleSizeChange(e){
          this.form.pageSize=e;
          this.getdata()
      },
    fj(row) {
      this.form1 = JSON.parse(JSON.stringify(row));
      this.form1.fjly = "";
      this.form1.status = "1";
      this.dialogVisible1 = true;
    },
    async fjqd() {
      const res = await service.post("/index/adduser", this.form1);
      console.log(res);
      if (res.code == 200) {
        this.$message.success("修改成功");
        this.dialogVisible1 = false;
        this.getdata();
      }
    },
    async shenheqd() {
      const res = await service.post("/index/adduser", this.form1);
      console.log(res);
      if (res.code == 200) {
        this.$message.success("修改成功");
        this.dialogVisible = false;
        this.getdata();
      }
    },
    sh(row) {
      this.form1 = JSON.parse(JSON.stringify(row));

      this.form1.status = "";
      this.dialogVisible = true;
    },
    handleClose() {
      this.dialogVisible = false;
    },
    handleClose1() {
      this.dialogVisible1 = false;
    },
    chongzhi() {
      this.form = {
        username: "",
        pageNum: 1,
        pageSize: 10,
      };
      this.getdata();
    },
    chaxun() {
      this.getdata();
    },
    async getdata() {
      const res = await service.get("/index/userlist", {
        params: this.form,
      });
      console.log(res);
      this.tabledata = res.data;
      this.total = res.total;
    },
  },
};
</script>
<style scoped>
</style>